package com.sy.controller;

import com.sy.dto.PageBean;
import com.sy.entity.Question;
import com.sy.service.QuestionService;
import com.sy.vo.QuestionVo;
import com.sy.vo.StuAndTnoVo;
import com.sy.vo.StudentPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:fma
 * @Date: 2021/10/15 11:03
 */
@RestController
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    /**
     * 查询作业操作
     * @param studentPageVo 当前学生的信息的分页封装模型
     * @return 作业信息
     */
    @RequestMapping(value = "questions", method = RequestMethod.POST)
    public PageBean<Question> getQuestisonBySno(@RequestBody StudentPageVo studentPageVo) {
        return questionService.getQuestisonBySno(studentPageVo);
    }

    /**
     * 判断是否存在
     * @param stuAndTnoVo 当前学生的信息的分页封装模型
     * @return 作业信息
     */
    @RequestMapping(value = "teachers", method = RequestMethod.POST)
    public boolean  isTeacherExists(@RequestBody StuAndTnoVo stuAndTnoVo) {
        return questionService.isTeacherExists(stuAndTnoVo);
    }

    /**
     * 关联教师和学生查询作业状态操作
     * @param stuAndTnoVo 当前学生的信息的分页封装模型
     * @return 作业信息
     */
    @RequestMapping(value = "questionsStatus", method = RequestMethod.POST)
    public PageBean<Question> getQuestionByTno(@RequestBody StuAndTnoVo stuAndTnoVo) {
        return questionService.getQuestionByTno(stuAndTnoVo);
    }

    /**
     * 获取当前学生的作业状态
     * 前端请求路劲  http://localhost:8888/status?sno=2&pageNo=&oageNum=
     */
    @RequestMapping(value = "questions", method = RequestMethod.GET, params = {"sno","teacherName","pageNo","pageNum"})
    public PageBean<Question> getQuestionsLikeName(@RequestParam("sno") Integer sno,
                                               @RequestParam("teacherName") String teacherName,
                                               @RequestParam("pageNo") Integer pageNo,
                                               @RequestParam("pageNum") Integer pageNum) {
        return questionService.getQuestionsLikeName(sno,teacherName,pageNo,pageNum);
    }

    /**
     * 插入问题操作
     * @param questionVo 问题模型
     * @return
     * http://localhost:8888/addQuestion
     */
    @RequestMapping(value = "addQuestion", method = RequestMethod.POST)
    public boolean addQuestion(@RequestBody QuestionVo questionVo) {
        System.out.println();
        return questionService.addQuestion(questionVo);
    }
    /**
     * 查询问题操作
     * @Author 范富强
     * @param tno 教师的教工号
     * @return 问题信息
     */
    @RequestMapping(value = "questions/teacherId", method = RequestMethod.GET,params = {"tno","pageNo","pageNum"})
    public PageBean<Question> getQuestisonsByTno(@RequestParam("tno") Integer tno,
                                                 @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                                                 @RequestParam(value = "pageNum",required = false,defaultValue = "5") Integer pageNum) {
        return questionService.getQuestisonsByTno(tno,pageNo,pageNum);
    }

    /**
     * 查询问题的数量操作
     * @param tno 教师工号
     * @return 问题总数
     */
    @RequestMapping(value = "countquestions", method = RequestMethod.GET,params ="tno")
    public Integer CountQuestionByTno(Integer tno) {
        return questionService.CountQuestionByTno(tno);
    }
}
